package Controllers;

import java.sql.SQLException;
import Database.mysqlConnection;
import MessagePacks.UpdatePack;
import entities.*;

/**
 *@author Juan Alapin - 324507516
 *@author Giora Yaffe - 036551281
 *@author Shachar Gritzman - 300174026
 *@author Nir Porat - 021515580
*/
public class CProcessController
{

	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructor
	 */
	public CProcessController(){

	}
	
	/**
	 * Update the position of the Execution Leader
	 * @param workerID:int - The worker ID
	 * @param procID:int - The process ID
	 * @param SqlDB:mysqlConnection - SQL DataBase
	 */
	public void updateExecLdr(int workerID, int procID, mysqlConnection SqlDB){
		SqlDB.updateExecldr(workerID,procID);
	}
	
	/**
	 * Determine Tester for a process
	 * @param procID:int - The process ID
	 * @param workerID:int - The worker ID
	 * @param SqlDB:mysqlConnection - SQL DataBase
	 */
	public void setTester(int procID, int workerID, mysqlConnection SqlDB){
		SqlDB.setTester(procID, workerID);
	}
	
	/**
	 * Add new process to the DataBase
	 * @param reqID:int - Request's ID
	 * @param pr:CProcessRequest
	 * @param SqlDB:mysqlConnection - SQL DataBase
	 * @throws SQLException
	 */
	public void addNewProcess(int reqID,CProcessRequest pr,mysqlConnection SqlDB) throws SQLException{
		SqlDB.addProcessToDB(reqID,pr.getinitatorID());
	}
	
	/**
	 * Change the phase to a different phase
	 * @param updPack:UpdatePack
	 * @param SqlDB:mysqlConnection - SQL DataBase
	 */
	public void updatePhase(UpdatePack updPack,mysqlConnection SqlDB){
		SqlDB.updateProcessPhase(updPack.getProcId(), updPack.getPhaseNum());

	}
	
	/**
	 * Update the Process responsible
	 * @param procID:int - The process ID
	 * @param Ok:int
	 * @param SqlDB:mysqlConnection - SQL DataBase
	 */
	public void updateProcessResponsibleOk(int procId, int Ok, mysqlConnection SqlDB){
		SqlDB.updateProcessResponsible(procId, Ok);
	}
	
	/**
	 * Update status
	 * @param statusPack:UpdatePack
	 * @param SqlDB:mysqlConnection - SQL DataBase
	 */
	public void updateStatus(UpdatePack statusPack ,mysqlConnection SqlDB){
		SqlDB.updateProcessStatus(statusPack.getProcId(),statusPack.getStatus());
	}
	
	/**
	 * Get the time of a process
	 * @param procID:int - The process ID
	 * @param SqlDB:mysqlConnection - SQL DataBase
	 * @return 
	 * @throws SQLException
	 */
	public int getTimeOfPros(int procID,mysqlConnection SqlDB) throws SQLException{
		return SqlDB.getTimeProc(procID);
	}
	
}

